﻿<?php
include 'util.php';

//重定向浏览器
if($_POST["name"]==""){
	header("Location: http://www.baidu.com");
	//确保重定向后，后续代码不会被执行
	exit;
}

// 读游戏用户位置信息
$myFile = file_get_contents('src\json\gameStatus.json');
$myDataArr = json_decode(prepareJSON($myFile), true); 
$cards = $myDataArr['players'];
//$cards = json_encode($myDataArr['users']);
$userID =0;
$countUser =0;

for ($i=0; $i<count($myDataArr['players']); $i++) {
	$myDataArr['players'][$i]['name']=urlencode($myDataArr['players'][$i]['name']);
	if($myDataArr['players'][$i]['name'] == ''){
		$userID = $i+1;
		$myDataArr['players'][$i]['name']=urlencode($_POST["name"]);
		break;
	}
	$countUser++;
}

// 用户已满
if($countUser > 5){
	header("Location: http://localhost/error.php");
	exit;
}

file_put_contents('src\json\gameStatus.json',urldecode(json_encode($myDataArr)));

$msg = ',{"text":"'.$_POST["name"].'加入了游戏，坐在'.$userID.'号位。"}]}';
writeGameLog('src\json\gameLog.json',$msg);
$userID=2;
$seat=array($userID);
for($i=1;$i<6;$i++){
	$seat[$i]=$userID + $i;
	if($seat[$i] > 6){
		$seat[$i]=$seat[$i] - 6;
	}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<html>
<head>
    <title>技术测试</title>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
		<meta content="zh-cn" http-equiv="Content-Language">
    <script type="text/javascript" src="src/js/jquery-1.7.1.js"></script>
    <script type="text/javascript" src="src/js/jquery-ui-1.8.17.custom.min.js"></script>
    <script type="text/javascript" src="src/js/common.js"></script>
    <link id="css_common" type="text/css" charset="utf-8" rel="stylesheet" href="src/css/common.css">
    <link type="text/css" rel="stylesheet" href="src/css/jquery-ui-1.8.17.custom.css">
    <script language=javascript>
    </script>
</head>

<body>
<span><input id="card_target" type="hidden" name='card_target' class='person' value="司马懿"></input></span>
<span><input id="log_count" type="hidden" name='log_count' class='person' value="0"></input></span>
<span><input id="used_card" type="hidden" name='used_card' class='person' value="0"></input></span>
<span><input id="user_id_1" type="hidden" name='used_card' class='person' value="user<?php print $seat[1] ?>"></input></span>
<span><input id="user_id_2" type="hidden" name='used_card' class='person' value="user<?php print $seat[2] ?>"></input></span>
<span><input id="user_id_3" type="hidden" name='used_card' class='person' value="user<?php print $seat[3] ?>"></input></span>
<span><input id="user_id_4" type="hidden" name='used_card' class='person' value="user<?php print $seat[4] ?>"></input></span>
<span><input id="user_id_5" type="hidden" name='used_card' class='person' value="user<?php print $seat[5] ?>"></input></span>
<div class="user1" id="user<?php print $seat[1] ?>">
    <button id="user_name" class="opponent_equip" disabled="disabled"></button>
    <button id="force" class="opponent_force" disabled="disabled"></button>
    <button id="name" class="opponent_name" disabled="disabled" title="dddd"></button>
    <button name="card_name" class="opponent_card_name" disabled="disabled">牌</button>
    <button id="card_count" class="opponent_card_count" disabled="disabled"></button>
    <button name="blood" class="opponent_card_name" disabled="disabled">血</button>
    <button id="blood" class="opponent_blood" disabled="disabled"></button>
    <button id="weapon" class="opponent_equip" disabled="disabled"></button>
    <button id="armor" class="opponent_equip" disabled="disabled"></button>
    <button id="defensive_horse" class="opponent_equip" disabled="disabled"></button>
    <button id="offensive_horse" class="opponent_equip" disabled="disabled"></button>
    <button id="status1" class="opponent_status" disabled="disabled"></button>
    <button id="status2" class="opponent_status" disabled="disabled"></button>
    <button id="status3" class="opponent_status" disabled="disabled"></button>
    <button id="status4" class="opponent_status" disabled="disabled"></button>
</div>
<div class="user2" id="user<?php print $seat[2] ?>">
    <button id="user_name" class="opponent_equip" disabled="disabled"></button>
    <button id="force" class="opponent_force" disabled="disabled"></button>
    <button id="name" class="opponent_name" disabled="disabled"></button>
    <button name="card_name" class="opponent_card_name" disabled="disabled">牌</button>
    <button id="card_count" class="opponent_card_count" disabled="disabled"></button>
    <button name="blood" class="opponent_card_name" disabled="disabled">血</button>
    <button id="blood" class="opponent_blood" disabled="disabled"></button>
    <button id="weapon" class="opponent_equip" disabled="disabled"></button>
    <button id="armor" class="opponent_equip" disabled="disabled"></button>
    <button id="defensive_horse" class="opponent_equip" disabled="disabled"></button>
    <button id="offensive_horse" class="opponent_equip" disabled="disabled"></button>
    <button id="status1" class="opponent_status" disabled="disabled"></button>
    <button id="status2" class="opponent_status" disabled="disabled"></button>
    <button id="status3" class="opponent_status" disabled="disabled"></button>
    <button id="status4" class="opponent_status" disabled="disabled"></button>
</div>
<div class="user3" id="user<?php print $seat[3] ?>">
    <button id="user_name" class="opponent_equip" disabled="disabled"></button>
    <button id="force" class="opponent_force" disabled="disabled"></button>
    <button id="name" class="opponent_name" disabled="disabled"></button>
    <button name="card_name" class="opponent_card_name" disabled="disabled">牌</button>
    <button id="card_count" class="opponent_card_count" disabled="disabled"></button>
    <button name="blood" class="opponent_card_name" disabled="disabled">血</button>
    <button id="blood" class="opponent_blood" disabled="disabled"></button>
    <button id="weapon" class="opponent_equip" disabled="disabled"></button>
    <button id="armor" class="opponent_equip" disabled="disabled"></button>
    <button id="defensive_horse" class="opponent_equip" disabled="disabled"></button>
    <button id="offensive_horse" class="opponent_equip" disabled="disabled"></button>
    <button id="status1" class="opponent_status" disabled="disabled"></button>
    <button id="status2" class="opponent_status" disabled="disabled"></button>
    <button id="status3" class="opponent_status" disabled="disabled"></button>
    <button id="status4" class="opponent_status" disabled="disabled"></button>
</div>
<div class="user4" id="user<?php print $seat[4] ?>">
    <button id="user_name" class="opponent_equip" disabled="disabled"></button>
    <button id="force" class="opponent_force" disabled="disabled"></button>
    <button id="name" class="opponent_name" disabled="disabled"></button>
    <button name="card_name" class="opponent_card_name" disabled="disabled">牌</button>
    <button id="card_count" class="opponent_card_count" disabled="disabled"></button>
    <button name="blood" class="opponent_card_name" disabled="disabled">血</button>
    <button id="blood" class="opponent_blood" disabled="disabled"></button>
    <button id="weapon" class="opponent_equip" disabled="disabled"></button>
    <button id="armor" class="opponent_equip" disabled="disabled"></button>
    <button id="defensive_horse" class="opponent_equip" disabled="disabled"></button>
    <button id="offensive_horse" class="opponent_equip" disabled="disabled"></button>
    <button id="status1" class="opponent_status" disabled="disabled"></button>
    <button id="status2" class="opponent_status" disabled="disabled"></button>
    <button id="status3" class="opponent_status" disabled="disabled"></button>
    <button id="status4" class="opponent_status" disabled="disabled"></button>
</div>
<div class="user5" id="user<?php print $seat[5] ?>">
    <button id="user_name" class="opponent_equip" disabled="disabled"></button>
    <button id="force" class="opponent_force" disabled="disabled"></button>
    <button id="name" class="opponent_name" disabled="disabled"></button>
    <button name="card_name" class="opponent_card_name" disabled="disabled">牌</button>
    <button id="card_count" class="opponent_card_count" disabled="disabled"></button>
    <button name="blood" class="opponent_card_name" disabled="disabled">血</button>
    <button id="blood" class="opponent_blood" disabled="disabled"></button>
    <button id="weapon" class="opponent_equip" disabled="disabled"></button>
    <button id="armor" class="opponent_equip" disabled="disabled"></button>
    <button id="defensive_horse" class="opponent_equip" disabled="disabled"></button>
    <button id="offensive_horse" class="opponent_equip" disabled="disabled"></button>
    <button id="status1" class="opponent_status" disabled="disabled"></button>
    <button id="status2" class="opponent_status" disabled="disabled"></button>
    <button id="status3" class="opponent_status" disabled="disabled"></button>
    <button id="status4" class="opponent_status" disabled="disabled"></button>
</div>
<div class="test" id="test">
    <p><?php echo "技术测试 : ";?><span id="userName" style="color:red"><?php echo $_POST["name"]; ?></span></p>
    <button name="weapon" onclick="test()" title="反馈——你可以立即从对你造成伤害的来源处获得一张牌。">黑桃5 【青龙偃月刀】</button>
    <button name="weapon2" onclick="test2()">去牌</button>
    <button name="weapon3" onclick="readChatLog();readGameLog();">读文件</button>
    <button name="weapon3" onclick="test4()">测试加载英雄牌</button>
    <button name="weapon3" onclick="setPlayerInfo()">设置用户信息</button>
    <button onclick="selectHeros()">选英雄</button>
</div>
<div class="owner" id="user<?php print $seat[0] ?>">
    <div class="owner_equip" id="equip">
			<button id="owner_weapon" class="equip_text" disabled="disabled">武器</button>
			<button id="owner_armor" class="equip_text" disabled="disabled">防具</button>
			<button id="owner_offensive_horse" class="equip_text" disabled="disabled">＋马</button>
			<button id="owner_defensive_horse" class="equip_text" disabled="disabled">－马</button>
	    <button id="owner_status1" class="owner_status"></button>
	    <button id="owner_status2" class="owner_status"></button>
	    <button id="owner_status3" class="owner_status"></button>
	    <button id="owner_status4" class="owner_status"></button>
		</div>
    <div class="owner_card" id="owner_card">
    </div>
    <div class="owner_cmd" id="owner_cmd">
        <!--<button name='weapon' class='role' disabled="disabled">反贼</button>-->
        <button name='weapon' class='cmd'>回合结束</button>
        <br/>
        <button name='weapon' class='cmd' onclick="drawCard(1)">摸牌</button>
        <button name='weapon' class='cmd'>判定</button>
        <br/>
        <button name='weapon' class='cmd' onclick="">加血</button>
        <button name='weapon' class='cmd' style="color:blue">减血</button>
    </div>

    <div class="owner_person" id="person_skill">
    	<button id="owner_force" class="opponent_force" disabled="disabled">魏</button>
        <button id='owner_name' class='person' disabled="disabled">司马懿</button>
        <button id='owner_bloodNow' class='person_blood_normal' disabled="disabled">★★☆</button>
        <br/>
        <button id='owner_skill_1' class='person_skill' title="你可以立即从对你造成伤害的来源处获得一张牌。">反馈</button>
        <button id='owner_skill_2' class='person_skill' title="在任意角色的判定牌生效前，你可以打出一张手牌代替之。">鬼才</button>
        <!--<button id='owner_skill_3' class='person_skill' title="你可以立即从对你造成伤害的来源处获得一张牌。">反馈</button>
        <button id='owner_skill_4' class='person_skill' title="在任意角色的判定牌生效前，你可以打出一张手牌代替之。">鬼才</button>
        -->
    </div>
</div>
<div class="gameLog" id="gameLog">
</div>
<div class="chatBox_msgList" id="chatBox_msgList">
</div>
<div class="chatBox_msgEdit" id="chatBox_msgList_4">
    <textarea id="chatWindows" rows="2" cols="34"></textarea>
    <span style="color:red;font-size:12px;font-weight:bold;">按Ctrl+Enter发送</span>
</div>
<!--<div class="playCard_div" id="playCard">
</div>-->
<script>

</script>


</body>
</html>
